home *** CD-ROM | disk | FTP | other *** search
- Glydo.TeasersManager = Prototype.Class.create(Glydo.EventSource,{
-
- initialize: function($super,application) {
- $super();
- this.application = application;
- this.localizedStrings = new Glydo.Utils.LocalizedBundle(document);
- this.paneTitle = this.localizedStrings.get("vertical_pane.teaser.title");
- this.anchor = document.getElementById("status-bar");
- this.teaserRecs = null;
- this.lastTeaserMillis = Date.now();
- },
-
-
- onCurrentDocumentChanged: function(docEntry) {
- // Make sure the teaser is closed
- this.application.detachedPopupsManager.closePopup('teaser',Glydo.DetachedPopupsManager.CLOSE_REASONS.CONTEXT_CHANGE);
- },
-
- onCurrentProcessedDocumentChanged: function(docEntry) {
- // Make sure the teaser is closed
- this.application.detachedPopupsManager.closePopup('teaser',Glydo.DetachedPopupsManager.CLOSE_REASONS.CONTEXT_CHANGE);
- this.update(docEntry);
- },
-
- update: function(docEntry) {
- if (!docEntry) {
- return;
- }
-
- // If another popup is open, return immediately
- if (this.application.detachedPopupsManager.isPopupOpen()) {
- return;
- }
- // Get the earliest time a teaser may be shown
- var minTeaserIntervalMillis = Glydo.Prefs.teaser_min_interval_millis;
- if (minTeaserIntervalMillis === null || minTeaserIntervalMillis < 0) {
- return;
- }
- if (this.lastTeaserMillis !== null) {
- var cur = Date.now();
- if (cur < this.lastTeaserMillis + minTeaserIntervalMillis) {
- return;
- }
- }
-
- // We are ok to show a teaser in terms of time elapsed
- // We now obtain the list of candidate recommendations for the teaser, filtering those
- // that we have already shown rececntly.
- var greatRecs = docEntry.selectRecommendations(Glydo.TeasersManager.TOP_RECOMMENDATION_PANE_DEFS.filter);
- greatRecs = greatRecs.filter(function(rec) {
- return Glydo.LOGGING_DB.getRecLastViewedInTeaserTime(rec.url) === null;
- },this);
-
- // If there are no results, we don't show a teaser
- if (greatRecs.length == 0) {
- return;
- }
-
- // Otherwise, we show the best great rec as a teaser
- this.teaserRecs = [greatRecs[0]];
-
- var contentsType = (this.teaserRecs[0].contextRelation == "same_product_alternative_offer") ? "product_offers" : this.teaserRecs[0].contentType;
- var title = this.localizedStrings.get("vertical_pane.teaser." + contentsType + ".title");
- if (!title) {
- title = this.paneTitle;
- }
- this.application.detachedPopupsManager.focusWindowOrTogglePopup({
- name: "teaser",
- contentsType: contentsType,
- title: title,
- filter: this.teaserRecs,
- adFilter: this.selectAdFilter(this.teaserRecs[0])
- },{
- anchor: this.anchor,
- position: 'before_end',
- auto_hide: Glydo.Prefs.teaser_auto_hide_interval_millis,
- realEstateKind: 'TEASER'
- });
- this.lastTeaserMillis = Date.now();
- },
-
- selectAdFilter: function(rec) {
- if (rec.contentType == 'product' || rec.contentType == 'ad') {
- return null;
- }
- return Glydo.TeasersManager.TEASER_ADS_FILTER;
- },
-
- onPopupClosed: function(name,reason,time_open_millis) {
- if (name != "teaser") {
- return;
- }
- // If the teaser was closed as a result of direct
- // user interaction or if it was shown for enough time,
- // mark the rec as shown in the ticker
- if (reason.interaction || time_open_millis > Glydo.Prefs.teaser_min_open_time_for_ack_millis) {
- this.teaserRecs.forEach(function(rec) {
- Glydo.LOGGING_DB.markRecAsViewedInTeaser(rec.url,rec.receivedTime);
- },this);
- }
- this.teaserRecs = null;
- },
-
- });
-
- Glydo.TeasersManager.TEASER_ADS_FILTER = ({
- condition: {
- contentType: ["ad","product"]
- },
- orderBy: "-relevanceScore",
- limit: 20
- });
-
- Glydo.TeasersManager.TEASER_CONTENT_TYPES = [
- "rss", "info", "news", "video", "other", "twitter"
- ];
-
- Glydo.TeasersManager.TOP_RECOMMENDATION_PANE_DEFS = ({
- name: "teaser",
- filter: {
- condition: function (rec) {
- var valid = rec.isHurray && rec.title;
- if (rec.contextRelation == "related_content") {
- valid = valid &&
- rec.excerpt &&
- rec.thumbnails &&
- rec.thumbnails.length > 0;
- } else if (rec.contextRelation == "same_product_alternative_offer"){
- valid = valid &&
- rec.origin &&
- rec.priceValue &&
- rec.contextItem &&
- rec.contextItem.annotation &&
- rec.contextItem.annotation.price &&
- rec.priceValue < rec.contextItem.annotation.price;
- } else {
- valid = false;
- }
- return valid;
- },
- orderBy: "-relevanceScore"
- }
- });
-